// --------------------------------------------------------------------------------------------------------------------
// <copyright file="IInstrument.cs" company="Open Trader">
//   Copyright (c) David Denis (david.denis@systemathics.com)
// </copyright>
// <summary>
//   |  Open Trader - The Open Source Systematic Trading Platform
//   |
//   |  This program is free software: you can redistribute it and/or modify
//   |  it under the terms of the GNU General Public License as published by
//   |  the Free Software Foundation, either version 2 of the License, or
//   |  (at your option) any later version.
//   |
//   |  This program is distributed in the hope that it will be useful,
//   |  but WITHOUT ANY WARRANTY; without even the implied warranty of
//   |  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//   |  GNU General Public License for more details.
//   |
//   |  You should have received a copy of the GNU General Public License
//   |  along with this program.  If not, see http://www.gnu.org/licenses
//   |
//   |  Up to date informations about Open Trader can be found at :
//   |    http://opentrader.org
//   |    http://opentrader.codeplex.com
//   |
//   |  For professional services, please visit us at :
//   |    http://www.systemathics.com
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Org.OpenTrader.Framework.Forge.Interfaces
{
    #region Usings

    using System;

    using Org.OpenTrader.Framework.Forge.Enums;
    using Org.OpenTrader.Framework.Forge.Events;

    #endregion

    /// <summary>
    /// The i instrument toolkit.
    /// </summary>
    public interface IInstrument
    {
        #region Events

        /// <summary>
        /// The feed handler.
        /// </summary>
        event EventHandler<FeedEventArgs> FeedEventCB;

        /// <summary>
        /// The order tracking handler.
        /// </summary>
        event EventHandler<OrderTrackingEventArgs> OrderTrackingEventCB;

        #endregion

        #region Properties

        /// <summary>
        /// Gets the Expo (aggregate several types of expositions)
        /// </summary>
        IExpo<IInstrumentExpoCell> Expo { get; }

        /// <summary>
        /// Gets FactorPrice
        /// </summary>
        double FactorPrice { get; }

        /// <summary>
        /// Gets related instrument static data
        /// </summary>
        IInstrumentStaticData InstrumentStaticData { get; }

        /// <summary>
        /// Gets the Market Book where updates are stored (bids/asks at several depths)
        /// </summary>
        IMarketBook MarketBook { get; }

        /// <summary>
        /// Gets the Market Fields FieldCache where updates are stored (open,high,low,close,wvap, ...) 
        /// </summary>
        IMarketFieldCache MarketFields { get; }

        /// <summary>
        /// Gets OrderTracker.
        /// </summary>
        IOrderTracker OrderTracker { get; }

        #endregion

        #region Public Methods

        /// <summary>
        /// Proceed to a "Buy" operation (create the order, send it to the exchange and handle async events accordingly)
        /// Uses OrdeTracker to do so
        /// </summary>
        /// <param name="type">
        /// </param>
        /// <param name="price">
        /// </param>
        /// <param name="quantity">
        /// </param>
        /// <param name="bookingPath">
        /// </param>
        /// <returns>
        /// A table of Guids representing the underlying orders on success, null otherwise
        /// </returns>
        Guid[] Buy(EOrderType type, double price, int quantity, string bookingPath);

        /// <summary>
        /// Cancel a priviously sent order
        /// </summary>
        /// <param name="id">
        /// </param>
        /// <returns>
        /// The cancel.
        /// </returns>
        bool Cancel(Guid id);

        /// <summary>
        /// Cancel all orders of this booking path
        /// </summary>
        /// <param name="bookingPath">
        /// </param>
        /// <returns>
        /// The cancel.
        /// </returns>
        int Cancel(string bookingPath);

        /// <summary>
        /// Cancel all orders still on market
        /// USes OrderTracker to do so
        /// </summary>
        /// <returns>
        /// The cancel all.
        /// </returns>
        int CancelAll();

        /// <summary>
        /// Cancel all buy orders still on market
        /// Uses OrdeTracker to do so
        /// </summary>
        /// <returns>
        /// The cancel all buy.
        /// </returns>
        int CancelAllBuy();

        /// <summary>
        /// Cancell all sell orders still on market
        /// Uses OrdeTracker to do so
        /// </summary>
        /// <returns>
        /// The cancel all sell.
        /// </returns>
        int CancelAllSell();

        /// <summary>
        /// The feed subscribe.
        /// </summary>
        /// <returns>
        /// The modify.
        /// </returns>
        /// <summary>
        /// The feed unsubscribe.
        /// </summary>
        /// <returns>
        /// </returns>
        /// <summary>
        /// Modify the order having that ID
        /// </summary>
        /// <param name="id">
        /// </param>
        /// <param name="price">
        /// </param>
        /// <param name="quantity">
        /// </param>
        /// <param name="bookingPath">
        /// </param>
        /// <returns>
        /// The modify.
        /// </returns>
        bool Modify(Guid id, double price, int quantity, string bookingPath);

        /// <summary>
        /// The feed subscribe.
        /// </summary>
        /// <returns>
        /// </returns>
        /// <summary>
        /// The feed unsubscribe.
        /// </summary>
        /// <returns>
        /// </returns>
        /// <summary>
        /// Proceed to a "Buy" operation (create the order, send it to the exchange and handle async events accordingly)
        /// Uses OrdeTracker to do so
        /// </summary>
        /// <param name="type">
        /// </param>
        /// <param name="price">
        /// </param>
        /// <param name="quantity">
        /// </param>
        /// <param name="bookingPath">
        /// </param>
        /// <returns>
        /// A table of Guids representing the underlying orders on success, null otherwise
        /// </returns>
        Guid[] Sell(EOrderType type, double price, int quantity, string bookingPath);

        /// <summary>
        /// Stop all subscriptions
        /// </summary>
        void Shutdown();

        #endregion
    }
}